<?php

class Comment_Controller extends Base_Controller {
	public $restful=true;

	public function post_index(){
		if (Session::token()==Input::get("csrf_token")){
			$comment = Archive::find(Input::get("archive_id"))->comment()->insert(array(
																																							"user_id" => Auth::user()->id,
																																							"body"    => Helper::formatcontent(Input::get("content"))
																																						));
			if (is_object($comment)){
				$notificationuser = Helper::getuname(Input::get("content") , Auth::user()->uname);
				foreach ($notificationuser as $user) {
					$user_id = User::where_uname($user)->first()->id;
					if ( is_null(Notification::where_user_id($user_id)->first()) ){
						Notification::insert(array(
																		"user_id"    => $user_id,
																		"archive_id" => Input::get("archive_id")
																	));
					}
				}
				return Redirect::to("/archive/" . Input::get("archive_id"));
			}
			else
				return "添加失败！";
		}else{
			return "系统禁止跨站提交！";
		}
	}
}